// 待审核
var tblWaitAudit;
// 待入库
var tblWaitStockIn;
// 入库中
var tblStockIning;
// 已入库
var tblStockIned;

// 商品选择
var prjSkuTable;

// 高级检索条件
var searchCondition = {
    "planInTimeStart" : "",
    "planInTimeEnd" : "",
    "factInTimeStart" : "",
    "factInTimeEnd" : "",
    "apprTimeStart" : "",
    "apprTimeEnd" : "",
    "stockinCode" : "",
    "wmsStockinCode" : "",
    "stockinType" : "",
    "storId" : "",
    "goodsCode" : "",
    "goodsName" : "",
    "skuCode" : "",
    "skuName" : ""
};

$(document).ready(function () {
    
    // 特殊符号校验
    $.validator.addMethod("checkLetter", function(value, element) {
        var regx = /^[0-9a-zA-Z\u4E00-\u9FA5\r\n\s/.]*$/; 
        return regx.test(value);
    }, "请输入数字，大小写字母，汉字");
    
    $("#newForm").validate({
        debug:true,
        errorPlacement: function(error, element)
        {
            error.insertAfter(element);
        }
    });
    
    $('.panel-default .datetimepicker-default').datetimepicker();

    // 默认待审核显示
    getWaitAudit();
    getCounts();
    // 按钮控制
    setPageElementStatus("stockInList");

   /**
     * 构建入库类型下拉列表(编辑页面)
     */
    $.ajax({
        type: "GET",
        url: "/stockIn/getStockinTypeList.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#stockinType_m option").remove();
                $("#stockinType_m").append("<option value=''>请选择</option>");
                
                // 构建入库类型下拉列表(高级查询)
                $("#stockinType option").remove();
                $("#stockinType").append("<option value=''>请选择</option>");

                $.each(data.data, function (n, value) {
                    $('#stockinType_m').append("<option value='" + value.typeCode +"'>" + value.typeName + "</option>");
                    $('#stockinType').append("<option value='" + value.typeCode +"'>" + value.typeName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    //构建供应商下拉列表,构建仓库下拉列表, 构建运输公司下拉列表
    initialBinding();
});


function initialBinding(){

    //构建供应商下拉列表

	$.ajax({
	    type: "GET",
	    url: "/suppliers/getSupplierList.action",
	    contentType: "application/json;charset=utf-8",
	    dataType: "json",
	    success: function (data) {
	        if (data.result == "success") {
	        	window.top.window.$("#suppId option").remove();
	        	window.top.window.$("#suppId").append("<option value=''>请选择</option>");
	            $.each(data.data, function (n, value) {
	            	window.top.window.$('#suppId').append("<option value='" + value.id +"'>" + value.name + "</option>");
	            });
	        } else {
	            window.top.window.showModalAlert(data.msg);
	        }
	    },
	    error: function (XMLHttpRequest, textStatus) {
	        if (XMLHttpRequest.status == 500) {
	            var result = eval("(" + XMLHttpRequest.responseText + ")");
	            alert(result.errorObject.errorText);
	        }
	    }
	});


    // 构建仓库下拉列表

	$.ajax({
	    type: "GET",
	    url : "/stock/getExtStor.action",
	    contentType: "application/json;charset=utf-8",
	    dataType: "json",
	    success: function (data) {
	        if (data.result == "success") {
	        	window.top.window.$("#storId option").remove();
	        	window.top.window.$("#storId").append("<option value=''>请选择</option>");
	            $.each(data.data, function (n, value) {
	            	window.top.window.$('#storId').append("<option value='" + value.storId +"'>" + value.storName + "</option>");
	            });
	            
	            window.top.window.$("#storId_m option").remove();
	            window.top.window.$("#storId_m").append("<option value=''>请选择</option>");
	            $.each(data.data, function (n, value) {
	            	window.top.window.$('#storId_m').append("<option value='" + value.storId +"' storCode='" + value.storCode + "'>" + value.storName + "</option>");
	            });
	        } else {
	            window.top.window.showModalAlert(data.msg);
	        }
	    },
	    error: function (XMLHttpRequest, textStatus) {
	        if (XMLHttpRequest.status == 500) {
	            var result = eval("(" + XMLHttpRequest.responseText + ")");
	            alert(result.errorObject.errorText);
	        }
	    }
	});


    // 构建运输公司下拉列表

	$.ajax({
	    type: "GET",
	    url: "/lgst/LgstList.action?length=-1",
	    contentType: "application/json;charset=utf-8",
	    dataType: "json",
	    success: function (data) {
	        if (data.result == "success") {
	            window.top.window.$("#lgstId option").remove();
	            window.top.window.$("#lgstId").append("<option value=''>请选择</option>");
	            $.each(data.data, function (n, value) {
	            	window.top.window.$('#lgstId').append("<option value='" + value.lgstId +"'>" + value.lgstName + "</option>");
	           });
	        } else {
	            window.top.window.showModalAlert(data.msg);
	        }
	    },
	    error : function (XMLHttpRequest, textStatus) {
	        if (XMLHttpRequest.status == 500) {
	            var result = eval("(" + XMLHttpRequest.responseText + ")");
	            alert(result.errorObject.errorText);
	        }
	    }
	});
}


// 设置高级查询条件
function setSearchCondition() {
    searchCondition = {
	    "planInTimeStart" : encodeURI($('#planInTimeStart').val()),
	    "planInTimeEnd" : encodeURI($('#planInTimeEnd').val()),
	    "factInTimeStart" : encodeURI($('#factInTimeStart').val()),
	    "factInTimeEnd" : encodeURI($('#factInTimeEnd').val()),
	    "apprTimeStart" : encodeURI($('#apprTimeStart').val()),
	    "apprTimeEnd" : encodeURI($('#apprTimeEnd').val()),
	    "stockinCode" : encodeURI($('#stockinCode').val()),
	    "wmsStockinCode" : encodeURI($('#wmsStockinCode').val()),
	    "stockinType" : encodeURI($('#stockinType').val()),
	    "storId" : encodeURI($('#storId').val()),
	    "goodsCode" : encodeURI($('#goodsCode').val()),
	    "goodsName" : encodeURI($('#goodsName').val()),
	    "skuCode" : encodeURI($('#skuCode').val()),
	    "skuName" : encodeURI($('#skuName').val())
    };
}

// 快速查询回车
$('#quickSearch').keydown(function(e){
    if (e.keyCode == 13 && $('#btnQuickSearch').is(":visible")) {
        $('#btnQuickSearch').click();
    }
});

// 快速查询按钮
$("#btnQuickSearch").click(function () {
	setSearchCondition();
	drawTable();
});

// 高级查询按钮
$("#advSearchSubmit").click(function () {
    setHidValue("frmAdvSearch");
    setSearchCondition();
    drawTable();
});

// 重置按钮
$("#advSearchReset").click(function() {
});

// 隐藏高级查询
$("#advSearchPanel").hide();
$("#btnAdvSearch").click(function () {
    if ($("#advSearchPanel").is(":hidden")) {
        $("#advSearchPanel").show();
        $("#btnQuickSearch").hide();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
        $(this).children("i:eq(0)").addClass("fa-angle-double-up");
    } else {
        $("#advSearchPanel").hide();
        $("#btnQuickSearch").show();
        $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
        $(this).children("i:eq(0)").addClass("fa-angle-double-down");
    }
});

// 高级查询区域内单击
$("#advSearchPanel").click(function () {
});

// tab切换事件
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
    
    switch ($(this).attr("id")) {
        case "waitAudit":  //待审核
            getWaitAudit();
            break;
        case "waitStockIn":  //已审核
            getWaitStockIn();
            break;
        case "stockIning":  //入库中
            getStockIning();
            break;
        case "stockIned":  //已入库
            getStockIned();
            break;
        default:
            break;
    }
    
    getCounts();
});

// tab显示时
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
    var tables = $.fn.dataTable.tables({
        visible : true,
        api : true
    });
    if (tables.length > 0) {
        $(tables).DataTable().columns.adjust();
    }
    $(tables).find("th.sorting_asc").removeClass("sorting_asc");
});

// 待审核列表
function getWaitAudit(){
    if (tblWaitAudit!=null && tblWaitAudit!=undefined && ""!=tblWaitAudit){
        tblWaitAudit.draw();
        return;
    }
    
    tblWaitAudit = $('#tblWaitAudit').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/stockIn/getStockInList.action",
            "data": function (d) {
                d.tabStockInStatus = "waitAudit";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ 
        	{"data" : "skuShow", "orderable" : false}, 
        	{"data" : "stockinCode"}, 
        	{"data" : "wmsStockinCode"}, 
        	{"data" : "stockinType",
                "render" : function(data, type, row, meta) {
	                if (row.stockinType == "pu") {
	                    return "采购入库";
	                } else {
	                    return "调拨入库";
	                }
	            }
        	}, 
        	{"data" : "storName"}, 
        	{"data" : "suppName"}, 
        	{"data" : "purcAmount",
                "render" : function(data, type, row, meta) {
                    var returnValue = "";
	                if (data != undefined && data != "" && data != null) {
	                    if (data == "0") {
	                        returnValue = "";
	                    } else {
	                        returnValue = data;
	                    }
	                } else {
	                    returnValue = "";
	                }
	                return returnValue;
                },
            }, 
            {"data" : "createTime"}, 
            {"data" : "apprTime"}, 
            {"data" : "planInTime"}, 
            {"data" : "factInTime"}, 
            {"data" : "lgstName"}, 
            {"data" : "lgstNo"}, 
            {"data" : "deliveryman"}, 
            {"data" : "deliverymanMobile"}, 
            {"data" : "deliverymanTel"}, 
            {"data" : "remark"}, 
            {"data" : "operation", "orderable" : false} 
        ],
        "columnDefs" : [ 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 1 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 2 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 3 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 4 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 5 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 6 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 7 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 8 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 9 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 10 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 11 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 12 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 13 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 14 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 15 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 16 ]}
        ],
        "order" : [ [ 7, "desc" ] ]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblWaitAudit").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 待入库列表
function getWaitStockIn(){
    if (tblWaitStockIn!=null && tblWaitStockIn!=undefined && ""!=tblWaitStockIn){
    	tblWaitStockIn.draw();
        return;
    }
    
    tblWaitStockIn = $('#tblWaitStockIn').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/stockIn/getStockInList.action",
            "data": function (d) {
                d.tabStockInStatus = "waitStockIn";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ 
        	{"data" : "skuShow", "orderable" : false}, 
        	{"data" : "stockinCode"}, 
        	{"data" : "wmsStockinCode"}, 
        	{"data" : "stockinType",
                "render" : function(data, type, row, meta) {
	                if (row.stockinType == "pu") {
	                    return "采购入库";
	                } else {
	                    return "调拨入库";
	                }
	            }
        	}, 
        	{"data" : "storName"}, 
        	{"data" : "suppName"}, 
        	{"data" : "purcAmount",
                "render" : function(data, type, row, meta) {
                    var returnValue = "";
	                if (data != undefined && data != "" && data != null) {
	                    if (data == "0") {
	                        returnValue = "";
	                    } else {
	                        returnValue = data;
	                    }
	                } else {
	                    returnValue = "";
	                }
	                return returnValue;
                },
            }, 
            {"data" : "createTime"}, 
            {"data" : "apprTime"}, 
            {"data" : "planInTime"}, 
            {"data" : "factInTime"}, 
            {"data" : "lgstName"}, 
            {"data" : "lgstNo"}, 
            {"data" : "deliveryman"}, 
            {"data" : "deliverymanMobile"}, 
            {"data" : "deliverymanTel"}, 
            {"data" : "remark"}, 
            {"data" : "operation", "orderable" : false} 
        ],
        "columnDefs" : [ 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 1 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 2 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 3 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 4 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 5 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 6 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 7 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 8 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 9 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 10 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 11 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 12 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 13 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 14 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 15 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 16 ]}
        ],
        "order" : [ [ 7, "desc" ] ]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblWaitStockIn").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 入库中列表
function getStockIning(){
    if (tblStockIning!=null && tblStockIning!=undefined && ""!=tblStockIning){
    	tblStockIning.draw();
        return;
    }
    
    tblStockIning = $('#tblStockIning').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/stockIn/getStockInList.action",
            "data": function (d) {
                d.tabStockInStatus = "stockIning";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ 
        	{"data" : "skuShow", "orderable" : false}, 
        	{"data" : "stockinCode"}, 
        	{"data" : "wmsStockinCode"}, 
        	{"data" : "stockinType",
                "render" : function(data, type, row, meta) {
	                if (row.stockinType == "pu") {
	                    return "采购入库";
	                } else {
	                    return "调拨入库";
	                }
	            }
        	}, 
        	{"data" : "storName"}, 
        	{"data" : "suppName"}, 
        	{"data" : "purcAmount",
                "render" : function(data, type, row, meta) {
                    var returnValue = "";
	                if (data != undefined && data != "" && data != null) {
	                    if (data == "0") {
	                        returnValue = "";
	                    } else {
	                        returnValue = data;
	                    }
	                } else {
	                    returnValue = "";
	                }
	                return returnValue;
                },
            }, 
            {"data" : "createTime"}, 
            {"data" : "apprTime"}, 
            {"data" : "planInTime"}, 
            {"data" : "factInTime"}, 
            {"data" : "lgstName"}, 
            {"data" : "lgstNo"}, 
            {"data" : "deliveryman"}, 
            {"data" : "deliverymanMobile"}, 
            {"data" : "deliverymanTel"}, 
            {"data" : "remark"}, 
            {"data" : "operation", "orderable" : false} 
        ],
        "columnDefs" : [ 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 1 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 2 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 3 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 4 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 5 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 6 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 7 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 8 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 9 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 10 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 11 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 12 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 13 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 14 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 15 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 16 ]}
        ],
        "order" : [ [ 7, "desc" ] ]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblStockIning").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 已入库列表
function getStockIned(){
    if (tblStockIned!=null && tblStockIned!=undefined && ""!=tblStockIned){
    	tblStockIned.draw();
        return;
    }
    
    tblStockIned = $('#tblStockIned').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000] ],
        "dom": '<"bottom"rtflp>',
        "searching": false,
        "scrollX": true,
        "scrollCollapse": true,
        "pagingType": "full_numbers",
        "deferRender": true,
        "ajax": {
            "url": "/stockIn/getStockInList.action",
            "data": function (d) {
                d.tabStockInStatus = "stockIned";
                d.quickSearch = encodeURI($('#quickSearch').val());
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ 
        	{"data" : "skuShow", "orderable" : false}, 
        	{"data" : "stockinCode"}, 
        	{"data" : "wmsStockinCode"}, 
        	{"data" : "stockinType",
                "render" : function(data, type, row, meta) {
	                if (row.stockinType == "pu") {
	                    return "采购入库";
	                } else {
	                    return "调拨入库";
	                }
	            }
        	}, 
        	{"data" : "storName"}, 
        	{"data" : "suppName"}, 
        	{"data" : "purcAmount",
                "render" : function(data, type, row, meta) {
                    var returnValue = "";
	                if (data != undefined && data != "" && data != null) {
	                    if (data == "0") {
	                        returnValue = "";
	                    } else {
	                        returnValue = data;
	                    }
	                } else {
	                    returnValue = "";
	                }
	                return returnValue;
                },
            }, 
            {"data" : "createTime"}, 
            {"data" : "apprTime"}, 
            {"data" : "planInTime"}, 
            {"data" : "factInTime"}, 
            {"data" : "lgstName"}, 
            {"data" : "lgstNo"}, 
            {"data" : "deliveryman"}, 
            {"data" : "deliverymanMobile"}, 
            {"data" : "deliverymanTel"}, 
            {"data" : "remark"}, 
            {"data" : "operation", "orderable" : false} 
        ],
        "columnDefs" : [ 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 1 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 2 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 3 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 4 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 5 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 6 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 7 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 8 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 9 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 10 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 11 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 12 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 13 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 14 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 15 ]}, 
        	{"className" : "truncate-text tooltip-column-detail", "targets" : [ 16 ]}
        ],
        "order" : [ [ 7, "desc" ] ]
    });
    
    // 文字过长截断显示悬浮框
    $("#tblStockIned").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });
    
}

// 重画表格
function drawTable() {
    $("div .active").each(function(){
        switch ($(this).attr("id")) {
            case "divWaitAudit":  //待审核
                tblWaitAudit.draw();
                break;
            case "divWaitStockIn":  //待出库
                tblWaitStockIn.draw();
                break;
            case "divStockIning":  //出库中
                tblStockIning.draw();
                break;
            case "divStockIned":  //已出库
                tblStockIned.draw();
                break;
            default:
                break;
        }
    });
 
    getCounts();
}

// 取得tab上面的条数
function getCounts(){
    var data = {quickSearch:encodeURI($('#quickSearch').val()), formJson:JSON.stringify(searchCondition)};
    
    $.ajax({
        type: "GET",
        url: "/stockIn/getStockInListCount.action",
        data: data,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#waitAudit").html("待审核(" + data.waitAuditCount + ")");
                $("#waitStockIn").html("待入库(" + data.waitStockInCount + ")");
                $("#stockIning").html("入库中(" + data.stockIningCount + ")");
                $("#stockIned").html("已入库(" + data.stockInedCount + ")");
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

// 单价，金额格式化
var numberParser = function(data){
    var returnValue = "-";
    var numberData = parseFloat(data);
    if(numberData===+numberData){
        returnValue = numberData.toFixed(2);
    }
    return returnValue;
};

// 子表格显示隐藏
$('.tablefirst tbody').on('click', 'td .sku-show', function () {
    var stockinId = $(this).attr('stockinId');
    var tr = $(this).closest('tr');
    var table;
    var row;
    var tablename =  "";
    $("div .active").each(function(){
        switch ($(this).attr("id")) {
        case "divWaitAudit":
            table = tblWaitAudit;
            row = tblWaitAudit.row(tr);
            tablename = "tblWaitAudit";
            break;
        case "divWaitStockIn":
            table = tblWaitStockIn;
            row = tblWaitStockIn.row(tr);
            tablename = "tblWaitStockIn";
            break;
        case "divStockIning":
            table = tblStockIning;
            row = tblStockIning.row(tr);
            tablename = "tblStockIning"
            break;
        case "divStockIned":
            table = tblStockIned;
            row = tblStockIned.row(tr);
            tablename = "tblStockIned";
            break;
        default:
            break;
        }
    });
    // 加载过，而且是显示的状态
    if ( row.child.isShown() ) {
        row.child.hide();
        tr.removeClass('shown');
        $(this).removeClass('fa-chevron-up');
        $(this).addClass('fa-chevron-down');
    } else {
        // 关闭其他
        $('#'+tablename+' tbody tr').each(function(){
            if ($(this).attr("role")=="row"){
                table.row($(this)).child.hide();
            }
        });
        $('.fa-chevron-up').addClass('fa-chevron-down');
        $('.fa-chevron-down').removeClass('fa-chevron-up');
        
        var temp = '<iframe id="contentFrame" name="contentFrame" style="width:100%;" frameborder="0" scrolling="auto" src="/views/stockIn/sonStockInList.html" width="100%" height="245"></iframe>';
        row.child(temp).show();
        tr.addClass('shown');
        $(this).addClass('fa-chevron-up');
        $(this).removeClass('fa-chevron-down');
        
        $('#stockin_id').val(stockinId);
    }
});

// 审核入库单
function operationAudit(btnAudit) {
    var stockinId = $(btnAudit).attr("stockinId");
    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type: "POST",
        url: "/stockIn/auditStockIn.action?stockinId=" + stockinId,
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success: function (json) {
        	loading.remove();
            if (json.result=="success") {
                window.top.window.showScoMessage('ok', '审核成功');
                drawTable();
            } else {
                window.top.window.showModalAlert(json.msg);
            }
        }
    });
}

// 删除入库单
function operationDel(btnDel) {
    var stockinId = $(btnDel).attr("stockinId");
    var stockInStatus = $(btnDel).attr("stockInStatus");
    window.top.window.showModalConfirm("是否确认删除", function() {
        getDeleteStockIn(stockinId, stockInStatus);
    });
}

// 删除入库单
function getDeleteStockIn(stockinId, stockInStatus) {
    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type: "POST",
        url: "/stockIn/deleteStockIn.action?stockinId=" + stockinId + "&stockInStatus=" + stockInStatus,
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success: function (json) {
        	loading.remove();
            if (json.result=="success") {
                window.top.window.showScoMessage('ok', '删除成功');
                drawTable();
            } else {
                window.top.window.showModalAlert(json.msg);
            }
        }
    });
}

// 弹出新增入库单页面
function addStockIn() {
    $('#editTitle').html("新建入库单");
    $('#stockin_id').val('');
    $('#suppId').attr("disabled",true); 
    var editDialog = window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
    editDialog.modal({show:true, backdrop:'static'});
    //刷新下拉列表
    initialBinding();
}
// 保存入库单
$("#btnSave").click(function () {
    window.top.window.returnCustomModalDialog();

    if(!$("#newForm").valid()) {
        window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
        return;
    }
    
    // 商品信息不能为空
    if ($("#tblStockInGoods tbody tr").length == 0) {
        window.top.window.showModalAlert("商品信息不能为空");
        window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
        return;
    }
    
    var checkFlg = true;
    $("#tblStockInGoods tbody tr").each(function(index,element){
        var stockinType = $('#stockinType_m').val();
        var purcPrice = $(".check-price",element).val();
        var qty = $(".check-number",element).val();
        var remark = $(".check-remark",element).val();
        
        if (qty == "") {
            checkFlg = false;
            window.top.window.showModalAlert("计划入库数量不能为空");
            return false;
        }

        if (purcPrice=="" || parseFloat(purcPrice)<0) {
            checkFlg = false;
            window.top.window.showModalAlert("入库单价不能为空并且必须大于等于零");
            return false;
        }
    });
    if (!checkFlg) {
        window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
        return;
    }

//    // 校验入库单价存在零的商品
//    var checkFlgIs = true;
//    $("#tblStockInGoods tbody tr").each(function(index,element){
//        var purcPrice = $(".check-price",element).val();
//
//        if (parseFloat(purcPrice) == 0) {
//            checkFlgIs = false;
//            return false;
//        }
//    });
//
//    var saveFlag = true;
//    if (!checkFlgIs) {
//
//        var vRes = confirm("入库单价存在为零商品，是否继续保存？");
//        if (vRes == true) {
//            saveFlag = true;
//        } else {
//            saveFlag = false;
//            var editDialog = window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
//            editDialog.modal({
//                show : true,
//                backdrop : 'static'
//            });
//        }
//    }
//
//    if (saveFlag) {

        // 构建JOSN数据
        var suppId = $('#suppId').val();
        var suppName = "";
        if ($('#suppId').val() != "") {
            suppName = $("#suppId").find("option:selected").text();
        }
        var lgstId = $('#lgstId').val();
        var lgstName = "";
        if ($('#lgstId').val() != "") {
            lgstName = $("#lgstId").find("option:selected").text();
        }
        var stockInGoodsVOList = new Array();
        $("#tblStockInGoods tbody tr").each(function (index, element) {
            var goodsObj = new Object();
            goodsObj.stockinSkuId = $(".get-stockInSkuId", element).html();
            goodsObj.goodsId = $(".get-goodsId", element).html();
            goodsObj.goodsCode = $(".get-goodsCode", element).html();
            goodsObj.goodsName = $(".get-goodsName", element).html();
            goodsObj.skuId = $(".get-skuId", element).html();
            goodsObj.skuCode = $(".get-skuCode", element).html();
            goodsObj.skuName = $(".get-skuName", element).html();
            goodsObj.inventoryType = $(".get-inventoryTypeCode", element).html();
            goodsObj.stanPurcPrice = $(".get-stanPurcPrice", element).html();
            goodsObj.purcPrice = $(".check-price", element).val() == "" ? "0" : $(".check-price", element).val();
            goodsObj.qty = $(".check-number", element).val();
            goodsObj.remark = $(".check-remark", element).val();
            stockInGoodsVOList.push(goodsObj);
        });
        var data = {
            "stockinId": $('#stockin_id').val(),
            "stockinType": $('#stockinType_m').val(),
            "suppId": suppId,
            "suppName": suppName,
            "planInTime": $('#planInTime').val(),
            "storId": $('#storId_m').val(),
            "storCode": $("#storId_m").find("option:selected").attr("storCode"),
            "storName": $("#storId_m").find("option:selected").text(),
            "lgstId": lgstId,
            "lgstName": lgstName,
            "lgstNo": $("#lgstNo").val(),
            "deliveryman": $('#deliveryman').val(),
            "deliverymanMobile": $('#deliverymanMobile').val(),
            "deliverymanTel": $('#deliverymanTel').val(),
            "remark": $('#remark').val(),
            "stockInGoodsVOList": stockInGoodsVOList
        }

        var url = "";
        if ($('#stockin_id').val() == "") {
            url = "/stockIn/insertStockIn.action";
        } else {
            url = "/stockIn/updateStockIn.action";
        }
        var newForm = window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
        var loading = window.top.window.getIndexBusyOverlay();
        $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8";
        $.ajax({
            type: "POST",
            url: url,
            data: JSON.stringify(data),
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            beforeSend:function(){
                if(loading) {
                	loading.settext("正在处理中，请稍后...");
                }
            },
            success: function (json) {
            	loading.remove();
                if (json.result == "success") {
                    newForm.modal('hide');
                    window.top.window.showScoMessage('ok', '保存成功');
                    drawTable();
                } else {
                    window.top.window.showModalAlert(json.msg);
                }
            }
        });

//    }

});

// 添加check
function addCheck() {
    $(".check-number").inputmask({
        regex : "^[1-9][0-9]{0,10}$",
        placeholder : ''
    });
    
    $(".check-price").inputmask("9{1,10}[.99]", {
        greedy : false,
        placeholder : ''
    });    
}

// 弹出修改入库单页面
function operationEdit(btnEdit) {
    $('#editTitle').html("修改入库单");

    $('#stockin_id').val($(btnEdit).attr("stockinId"));
    
    $.ajax({
        type: "POST",
        url: "/stockIn/getStockInInfo/" + $('#stockin_id').val() + ".action",
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                // 入库单信息
                $("#stockinType_m").val(data.data.stockinType);
                stockinTypeChange();
                $("#suppId").val(data.data.suppId);
                $('#planInTime').val(data.data.planInTime);
                $("#storId_m").val(data.data.storId);
                $("#lgstId").val(data.data.lgstId);
                $('#lgstNo').val(data.data.lgstNo);
                $('#deliveryman').val(data.data.deliveryman);
                $('#deliverymanMobile').val(data.data.deliverymanMobile);
                $('#deliverymanTel').val(data.data.deliverymanTel);
                $('#remark').val(data.data.remark);
                
                // 入库单商品信息
                for (var i=0; i<data.data.stockInGoodsVOList.length; i++) {
                    var stockInGoodsVO = data.data.stockInGoodsVOList[i];
                    
                    var trHtml = '';
                    trHtml+= "<tr>";
                    trHtml+= "<td class='get-goodsCode' title='"+ stockInGoodsVO.goodsCode +"'>" + stockInGoodsVO.goodsCode + "</td>";
                    trHtml+= "<td class='get-goodsName' title='" + stockInGoodsVO.goodsName + "'>" + stockInGoodsVO.goodsName + "</td>";
                    trHtml+= "<td class='get-skuCode' title='" + stockInGoodsVO.skuCode + "'>" + stockInGoodsVO.skuCode + "</td>";
                    trHtml+= "<td class='get-skuName' title='" + stockInGoodsVO.skuName + "'>" + stockInGoodsVO.skuName + "</td>";
                    trHtml+= "<td title='" + ((stockInGoodsVO.inventoryType=="zp")?"正品":"残次品") + "'>" + ((stockInGoodsVO.inventoryType=="zp")?"正品":"残次品") + "</td>";
                    trHtml+= "<td class='get-stanPurcPrice' align='right' title='" + stockInGoodsVO.stanPurcPrice + "'>" + stockInGoodsVO.stanPurcPrice + "</td>";
                    trHtml+= "<td title=''><input type='text' class='form-control check-price' style='text-align:right' maxlength='13' title='"+stockInGoodsVO.purcPrice+"' value='"+stockInGoodsVO.purcPrice+"' /></td>";
                    trHtml+= "<td title=''><input type='text' class='form-control check-number' style='text-align:right' maxlength='11' title='"+stockInGoodsVO.qty+"' value='"+stockInGoodsVO.qty+"' /></td>";
                    trHtml+= "<td title=''><input type='text' class='form-control calc-amount' style='text-align:right' maxlength='13' title='"+stockInGoodsVO.purcAmount+"' value='"+stockInGoodsVO.purcAmount+"' readonly /></td>";
                    trHtml+= "<td title=''><input type='text' class='form-control check-remark' style='min-width:100px;' maxlength='255' title = '"+stockInGoodsVO.remark+"' value='"+stockInGoodsVO.remark+"' /></td>";
                    trHtml+= "<td title=''><button type='button' class='btn btn-danger btn-xs' onclick='$(this).parents(\"tr\").get(0).remove();'><i class='fa fa-trash-o'></i>&nbsp;删除</button></td>";
                    trHtml+= "<td class='get-goodsId' style='display:none' title='" + stockInGoodsVO.goodsId + "'>" + stockInGoodsVO.goodsId + "</td>";
                    trHtml+= "<td class='get-skuId' style='display:none' title='" + stockInGoodsVO.skuId + "'>" + stockInGoodsVO.skuId + "</td>";
                    trHtml+= "<td class='get-inventoryTypeCode' style='display:none' title='" + stockInGoodsVO.inventoryType + "'>" + stockInGoodsVO.inventoryType + "</td>";
                    trHtml+= "<td class='get-stockInSkuId' style='display:none' title='" + stockInGoodsVO.stockinSkuId + "'>" + stockInGoodsVO.stockinSkuId + "</td>";
                    trHtml+= "</tr>";
                    $("#tblStockInGoods tbody").append(trHtml);
                }
                // 刷新下拉列表
                initialBinding()
                // 添加check
                addCheck();
                // 计算金额
                calcAmount();

                var editDialog = window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
                editDialog.modal({show:true, backdrop:'static'});
            }
        }
    });

    $('#divNewStockIn').modal('show');
}

// 弹出商品选择对话框
$("#btnAdd").click(function () {
    window.top.window.returnCustomModalDialog();
  
    var selDialog = window.top.window.borrowCustomModalDialog($("#divSelPrjSku"));
    selDialog.modal({show:true, backdrop:'static'});
    $('#divSelPrjSku').modal('show');
});

// 检索商品选择列表
var prjSkuFlg = false;
$("#btnPrjSkuSearch").click(function () {
    if (prjSkuFlg) {
        prjSkuTable.ajax.reload();
        return;
    }
    
    prjSkuTable = window.top.window.$('#tblSelPrjSku').DataTable({
        "paging": false,
        "processing": true,
        "serverSide": true,
        "dom": '<"bottom"rtflp>', 
        "searching": false,
        "deferRender": true,
        "ajax": {
            "url": "/stockIn/getPrjSkuList.action",
            "data": function ( d ) {
                var advData = {
                    "goodsCode": encodeURI(window.top.window.$('#skuGoodsCode').val().trim()),
                    "goodsName": encodeURI(window.top.window.$('#skuGoodsName').val().trim()),
                    "skuCode": encodeURI(window.top.window.$('#skuSkuCode').val().trim()),
                    "skuName": encodeURI(window.top.window.$('#skuSkuName').val().trim())
                };
                d.formJson = JSON.stringify(advData);
            }
        },
        "fnDrawCallback": function (oSettings) {
            window.top.window.$("#thSelPrjSku").removeClass("sorting_asc");
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [
            {"data": "skuCode",
                "render": function ( data, type, row, meta ) {
                              return '<input type="checkbox" name="chkItem" value="" />';
                          },
            "orderable": false},
            {"data": "goodsCode", "orderable": false},
            {"data": "goodsName", "orderable": false},
            {"data": "skuCode", "orderable": false},
            {"data": "skuName", "orderable": false},
            {"data": "",
                "render": function ( data, type, row, meta ) {
                              var returnHtml = '<select name="inventoryType" class="get-inventoryType">' +
                                                   '<option value="zp">正品</option>' +
                                                   '<option value="cc">残次品</option>' +
                                               '</select>';
                              return returnHtml;
                          },
            "orderable": false},
            {"data": "goodsId", "visible": false},
            {"data": "skuId", "visible": false},
            {"data": "stanPurcPrice", "visible": false},
            {"data": "salePrice", "visible": false}
        ]
    });
    
    prjSkuFlg = true;
});

// 全选，全不选商品
var checkboxes = window.top.window.document.getElementsByName('chkItem');
$("#chkAll").click(function () {
    for (var i = 0; i < checkboxes.length; i++) {
        var checkbox = checkboxes[i];
        if (!$(this).get(0).checked) {
            checkbox.checked = false;
        } else {
            checkbox.checked = true;
        }
    }
});

// 计算金额
function calcAmount() {
    $(".check-price,.check-number").change(function(){
        var trObj = $(this).parents("tr").eq(0);
        trObj.find(".calc-amount").val(trObj.find(".check-price").val()*100*trObj.find(".check-number").val()/100);
    });
}

// 添加入库单商品
$("#btnSaveSelPrjSku").click(function () {
    var inputSkuFlg = false;
    var checkSkuLock = false;
    window.top.window.$("#tblSelPrjSku tbody input[type='checkbox']:checked").each(function(k,v){
        var trObj = $(this).parents("tr").get(0);
        var rowData = prjSkuTable.row(trObj).data();
        var goodsCode = rowData.goodsCode;
        var goodsName = rowData.goodsName;
        var skuCode = rowData.skuCode;
        var skuName = rowData.skuName;
        var inventoryTypeCode = $('.get-inventoryType',trObj).val();
        var inventoryTypeName = $('.get-inventoryType',trObj).find("option:selected").text();
        var goodsId = rowData.goodsId;
        var skuId = rowData.skuId;
        var stanPurcPrice = rowData.stanPurcPrice;
        var salePrice = rowData.salePrice;
        
        var exsitSkuFlg = false;
        $("#tblStockInGoods tbody tr").each(function(index,element){
            var stockInGoodsCode = $(".get-goodsCode",element).html();
            var stockInSkuCode = $(".get-skuCode",element).html();
            var stockInInventoryTypeCode = $(".get-inventoryTypeCode",element).html();
            
            if (goodsCode==stockInGoodsCode && skuCode==stockInSkuCode && inventoryTypeCode==stockInInventoryTypeCode) {
                exsitSkuFlg = true;
                return false;
            }
        });
        
        if (!exsitSkuFlg) {
            var trHtml = '';
            trHtml+= "<tr>";
            trHtml+= "<td class='get-goodsCode'>" + goodsCode + "</td>";
            trHtml+= "<td class='get-goodsName'>" + goodsName + "</td>";
            trHtml+= "<td class='get-skuCode'>" + skuCode + "</td>";
            trHtml+= "<td class='get-skuName'>" + skuName + "</td>";
            trHtml+= "<td>" + inventoryTypeName + "</td>";
            trHtml+= "<td class='get-stanPurcPrice' align='right'>" + stanPurcPrice + "</td>";
            trHtml+= "<td><input type='text' class='form-control check-price' style='text-align:right' maxlength='13' value='' /></td>";
            trHtml+= "<td><input type='text' class='form-control check-number' style='text-align:right' maxlength='11' value='' /></td>";
            trHtml+= "<td><input type='text' class='form-control calc-amount' style='text-align:right' maxlength='13' value='' readonly /></td>";
            trHtml+= "<td><input type='text' class='form-control check-remark' style='min-width:100px;' maxlength='255' value='' /></td>";
            trHtml+= "<td><button type='button' class='btn btn-danger btn-xs' onclick='$(this).parents(\"tr\").get(0).remove();'><i class='fa fa-trash-o'></i>&nbsp;删除</button></td>";
            trHtml+= "<td class='get-goodsId' style='display:none'>" + goodsId + "</td>";
            trHtml+= "<td class='get-skuId' style='display:none'>" + skuId + "</td>";
            trHtml+= "<td class='get-inventoryTypeCode' style='display:none'>" + inventoryTypeCode + "</td>";
            trHtml+= "<td class='get-stockInSkuId' style='display:none'></td>";
            trHtml+= "</tr>";
            $("#tblStockInGoods tbody").append(trHtml);
        }else{
        	window.top.window.showModalAlert("列表中已存在规格编码为"+skuCode+"，商品名称为"+goodsName+"的商品，该商品添加失败！");
        	checkSkuLock = true;
        }
        
        inputSkuFlg = true;
    });

    // 添加check
    addCheck();
    // 计算金额
    calcAmount();
    
    if (!inputSkuFlg) {           
       window.top.window.showModalAlert("请选择一条商品");
       return;
    }
    if(!checkSkuLock){
    	window.top.window.returnCustomModalDialog();
        $('#divSelPrjSku').modal('hide');
    }
});

// 关闭新增入库单页面
$('#divNewStockIn').on('hidden.bs.modal', function () {
    $("#newForm")[0].reset();
    $("#tblStockInGoods").find("tbody").html("");
});

// 关闭新增入库单页面
$('#divNewStockIn').on('hide.bs.modal', function () {
    window.top.window.returnCustomModalDialog();
    $("#newForm").validate().clear();
});

// 关闭商品选择页面
$('#divSelPrjSku').on('hidden.bs.modal', function () {
    $("#frmSelPrjSku")[0].reset();
    $("#chkAll").removeAttr("checked"); 
    $("#tblSelPrjSku").find("tbody").html("");
});

// 关闭商品选择页面
$('#divSelPrjSku').on('hide.bs.modal', function () {
    window.top.window.returnCustomModalDialog();
    window.top.window.borrowCustomModalDialog($("#divNewStockIn"));
});

// 入库单类型变化时
function stockinTypeChange() {
    if ($('#stockinType_m').val() == "pu") {
        $('#suppId').attr("disabled",false); 
    } else {
        $('#suppId').attr("disabled",true); 
    }
}

// 入库单类型变化时
$('#stockinType_m').on('change', function() {
    window.top.window.$('#suppId').val(""); 
    if (window.top.window.$('#stockinType_m').val() == "pu") {
        window.top.window.$('#suppId').attr("disabled",false);
        // window.top.window.$(".check-price").each(function(index,element){
        //     $(this).attr("readonly",false);
        // });
    } else {
        window.top.window.$('#suppId').attr("disabled",true);
        // window.top.window.$(".check-price").each(function(index,element){
        //     $(this).val("");
        //     var trObj = $(this).parents("tr").eq(0);
        //     trObj.find(".calc-amount").val("");
        //     $(this).attr("readonly",true);
        // });
    }
});

// 弹出修改备注对话框
function operationUpdateRemark(btnEditRemark) {
    var stockinId = $(btnEditRemark).attr("stockinId");
    $.ajax({
        type: "POST",
        url: "/stockIn/getStockInInfo/" + stockinId + ".action",
        data: null,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $('#stockinId_r').val(stockinId);
                $('#stockinCode_r').val(data.data.stockinCode);
                $('#remark_r').val(data.data.remark);
                var editDialog = window.top.window.borrowCustomModalDialog($("#frmModifyStockIn_r"));
                editDialog.modal({show:true, backdrop:'static'});
            }
        }
    });

    $('#frmModifyStockIn_r').modal('show');
}

// 关闭修改备注对话框
$('#frmModifyStockIn_r').on('hidden.bs.modal', function () {
    $("#editForm_r")[0].reset();
});

// 关闭修改备注对话框
$('#frmModifyStockIn_r').on('hide.bs.modal', function () {
    window.top.window.returnCustomModalDialog();
    $("#editForm_r").validate().clear();
})

// 保存修改备注
$("#btnSave_r").click(function () {
    window.top.window.returnCustomModalDialog();

    if(!$("#editForm_r").valid()) {
        window.top.window.borrowCustomModalDialog($("#frmModifyStockIn_r"));
        return false;
    }

    var stockinId = $('#stockinId_r').val();
    var stockinCode = $('#stockinCode_r').val();
    var remark = $('#remark_r').val();
    var data = {
        "stockinId": stockinId,
        "stockinCode": stockinCode,
        "remark": remark
    }

    var edit=window.top.window.borrowCustomModalDialog($("#frmModifyStockIn_r"));

    $.ajaxSettings['contentType'] = "application/x-www-form-urlencoded; charset=utf-8";
    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type: "POST",
        url: "/stockIn/updateStockInRemark.action",
        data: JSON.stringify(data),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success: function (data) {
        	loading.remove();
            if (data.result == "success") {
                edit.modal('hide');
                $('#remark_r').val('');
                window.top.window.showScoMessage('ok', '保存成功');
                drawTable();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
});

// 导出
function exportStockIn() {
}

// 刷新
function refresh() {
 drawTable();
 }
    

